package cn.thoughtworks.school.programCenter.entities;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Setter
@Getter
@Builder
public class User {
    private String username;
    private List<Integer> roles;
    private Long id;

    public User(String username, Long id) {
        this.username = username;
        this.id = id;
    }

    public User() {
    }

    public User(String username, List<Integer> roles, Long id) {
        this.username = username;
        this.roles = roles;
        this.id = id;
    }

    public static List<User> convertMapsToUsers(List<Map> data) {
        return data.stream().map(item ->
                User.builder()
                        .id(Long.parseLong(item.get("id").toString()))
                        .username(item.get("username").toString())
                        .roles((List<Integer>) item.get("username"))
                        .build())
                .collect(Collectors.toList());
    }
}
